<ix-fieldset [title]="'Destination' | translate" [formGroup]="form">
  <ix-explorer
    formControlName="target_dataset"
    [label]="'Destination' | translate"
    [required]="true"
    [rootNodes]="[emptyRootNode]"
    [tooltip]="helptext.targetDatasetTooltip | translate"
    [nodeProvider]="nodeProvider()"
  ></ix-explorer>
  <ix-select
    formControlName="readonly"
    [label]="'Destination Dataset Read-only Policy' | translate"
    [options]="readonlyModes$"
    [required]="true"
    [tooltip]="helptext.readonlyTooltip | translate"
  ></ix-select>
  <ix-checkbox
    formControlName="encryption"
    [label]="'Encryption' | translate"
    [tooltip]="helptext.encryptionTooltip | translate"
  ></ix-checkbox>
  @if (hasEncryption) {
    <ix-checkbox
      formControlName="encryption_inherit"
      [label]="'Inherit Encryption' | translate"
      [tooltip]="helptext.encryptionInheritTooltip | translate"
    ></ix-checkbox>
  }

  @if (hasEncryption && !hasEncryptionInherit) {
    <ix-select
      formControlName="encryption_key_format"
      [label]="'Encryption Key Format' | translate"
      [options]="encryptionKeyFormats$"
      [required]="true"
      [tooltip]="helptext.encryptionKeyGenerateTooltip | translate"
    ></ix-select>
    @if (isHex) {
      <ix-checkbox
        formControlName="encryption_key_generate"
        [label]="'Generate Encryption Key' | translate"
        [tooltip]="helptext.encryptionKeyGenerateTooltip | translate"
      ></ix-checkbox>
    }
    @if (isHex && !form.value.encryption_key_generate) {
      <ix-input
        formControlName="encryption_key_hex"
        [label]="'Encryption Key' | translate"
        [tooltip]="helptext.encryptionKeyHexTooltip | translate"
      ></ix-input>
    }
    @if (!isHex) {
      <ix-input
        formControlName="encryption_key_passphrase"
        type="password"
        [label]="'Passphrase' | translate"
        [tooltip]="helptext.encryptionKeyPassphraseTooltip | translate"
      ></ix-input>
    }
    <ix-checkbox
      formControlName="encryption_key_location_truenasdb"
      [label]="'Store Encryption key in Sending TrueNAS database' | translate"
      [tooltip]="helptext.encryptionKeyLocationTruenasdbTooltip | translate"
    ></ix-checkbox>
    @if (!form.value.encryption_key_location_truenasdb) {
      <ix-input
        formControlName="encryption_key_location"
        [label]="'Encryption Key Location in Target System' | translate"
        [tooltip]="helptext.encryptionKeyLocationTooltip | translate"
      ></ix-input>
    }
  }

  <ix-checkbox
    formControlName="allow_from_scratch"
    [label]="'Replication from scratch' | translate"
    [tooltip]="helptext.allowFromScratchTooltip | translate"
  ></ix-checkbox>
  <ix-select
    formControlName="retention_policy"
    [label]="'Snapshot Retention Policy' | translate"
    [options]="retentionPolicies$"
    [required]="true"
    [tooltip]="helptext.retentionPolicyTooltip | translate"
  ></ix-select>
  @if (form.value.retention_policy === RetentionPolicy.Custom) {
    <div class="retention-policy">
      <ix-input
        formControlName="lifetime_value"
        type="number"
        [label]="'Snapshot Lifetime' | translate"
        [tooltip]="helptext.lifetimeValueTooltip | translate"
        [required]="true"
      ></ix-input>
      <ix-select
        formControlName="lifetime_unit"
        [label]="'Unit' | translate"
        [options]="lifetimeUnits$"
        [required]="true"
      ></ix-select>
    </div>
  }
</ix-fieldset>
